var Token = require("../model/token")
var ErrorCode = require('../api/errorCode')

module.exports= function(req,res,next){
    var token = req.headers['key']
    Token.findOne({token:token},function(err,t){
        if (t){
            req.userid = t.userid
            next()
        }else{
            res.json(401,ErrorCode.TokenAuthError)
            return
        }
    })
    
}